#include "StdAfx.h"
#include "CurveGenerator.h"


CurveGenerator::CurveGenerator(void)
{
}


CurveGenerator::~CurveGenerator(void)
{



}


void CurveGenerator::addPoint(Ogre::Vector3* point)
{

	points.push_back(point);
}


std::vector<Ogre::Vector3*>* CurveGenerator::generateCurve()
{
	//std::vector<Ogre::Vector3> * map = new std::vector<Ogre::Vector3>();

	int np = points.size();

	std::vector<Ogre::Vector3*> *generatedCurve = new std::vector<Ogre::Vector3*>();

	for(int i =0; i<np; i++)
	{
		for(float t =0; t<1; t = t+0.01)
			{
			//Vector pont = gorbe3->CurveArray(t,i);

			
			int a = i-1;
			if(a<0)a=0;;
			int b = i;
			int c = i+1;
			if (c>(np-1))c=np-1;
			int d = i+2;
			if (d==np) d=np-1;
			if (d==np+1) d=np-1;
			Ogre::Vector3 rt =( ((*points[b]))*2 + ((((*points[a]))*(-1)) + (*points[c])) * t + (*points[a]*2 - *points[b]*5 + *points[c]*4 - *points[d]) * t*t +
				((*points[a]*(-1)) + *points[b]*3- *points[c]*3 + *points[d]) * t*t*t)*0.5;


			Ogre::Vector3 * point = new Ogre::Vector3(rt);
			generatedCurve->push_back(point);
			
		
			}
	}

	return generatedCurve;

}

std::vector<Ogre::Vector3*>* CurveGenerator::generateCurve(std::vector<Ogre::Vector3*> *basePoints, float resolution)
{
	//std::vector<Ogre::Vector3> * map = new std::vector<Ogre::Vector3>();
	
	std::vector<Ogre::Vector3*> *generatedPoints = new std::vector<Ogre::Vector3*>();

	int np = basePoints->size();

	for(int i =0; i<np; i++)
	{
		for(float t =0; t<1; t = t+resolution)
			{
			//Vector pont = gorbe3->CurveArray(t,i);
			
			int a = i-1;
			if(a<0)a=0;;
			int b = i;
			int c = i+1;
			if (c>(np-1))c=np-1;
			int d = i+2;
			if (d==np) d=np-1;
			if (d==np+1) d=np-1;
			Ogre::Vector3 rt =( (*basePoints->at(b))*2 + ((((*basePoints->at(a)))*(-1)) + (*basePoints->at(c))) * t + 
				(*basePoints->at(a)*2 - *basePoints->at(b)*5 + *basePoints->at(c)*4 - *basePoints->at(d)) * t*t +
				((*basePoints->at(a)*(-1)) + *basePoints->at(b)*3- *basePoints->at(c)*3 + *basePoints->at(d)) * t*t*t)*0.5;

			Ogre::Vector3 * point = new Ogre::Vector3(rt);
			generatedPoints->push_back(point);
			
			}
	}

	return generatedPoints;

}